<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=452161
-->
<head>
  <title>nsIAccessibleEditableText chrome tests</title>
  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../events.js"></script>
  <script type="application/javascript"
          src="editabletext.js"></script>

  <script type="application/javascript">
    //gA11yEventDumpToConsole = true;
    //enableLogging("tree,verbose"); // debug

    function addTestEditable(aID, aTestRun, aBeforeContent, aAfterContent)
    {
      var et = new editableTextTest(aID);
      var startOffset = aBeforeContent ? aBeforeContent.length : 0;
      // XXX afterContent currently is not used

      //////////////////////////////////////////////////////////////////////////
      // setTextContents
      et.scheduleTest(et.setTextContents, "hello", startOffset);
      et.scheduleTest(et.setTextContents, "olleh", startOffset);
      et.scheduleTest(et.setTextContents, "", startOffset);

      //////////////////////////////////////////////////////////////////////////
      // insertText
      et.scheduleTest(et.insertText, "hello", startOffset, "hello");
      et.scheduleTest(et.insertText, "ma ", startOffset, "ma hello");
      et.scheduleTest(et.insertText, "ma", startOffset + 2, "mama hello");
      et.scheduleTest(et.insertText, " hello", startOffset + 10, "mama hello hello");

      // XXX: bug 452584

      //////////////////////////////////////////////////////////////////////////
      // deleteText
//      et.deleteText(0, 5, "hello hello");
//      et.deleteText(5, 6, "hellohello");
//      et.deleteText(5, 10, "hello");
//      et.deleteText(0, 5, "");

      //////////////////////////////////////////////////////////////////////////
      // copyNPasteText
//      et.copyNPasteText(0, 0, 0, "");
//      et.insertText("hello", 0, "hello");
//      et.copyNPasteText(0, 1, 0, "hhello");
//      et.copyNPasteText(5, 6, 6, "hhelloo");
//      et.copyNPasteText(3, 4, 1, "hehelloo");

      //////////////////////////////////////////////////////////////////////////
//      // cutNPasteText
//      et.cutNPasteText(0, 1, 1, "ehhelloo");
//      et.cutNPasteText(1, 2, 0, "hehelloo");
//      et.cutNPasteText(7, 8, 8, "hehelloo");

      aTestRun.add(et);
    }

    //gA11yEventDumpToConsole = true; // debug stuff

    function runTest()
    {
      var testRun = new editableTextTestRun();

      addTestEditable("input", testRun);
      addTestEditable("div", testRun);
      addTestEditable("divb", testRun, "pseudo element", "");
      addTestEditable("diva", testRun, "", "pseudo element");
      addTestEditable("divba", testRun, "before", "after");
      addTestEditable(getNode("frame").contentDocument, testRun);

      testRun.run(); // Will call SimpleTest.finish();
    }

    function doTest()
    {
      // Prepare tested elements.

      // Design mode on/off triggers an editable state change event on
      // the document accessible.
      var frame = getNode("frame");
      waitForEvent(EVENT_STATE_CHANGE, frame.contentDocument, runTest);
      frame.contentDocument.designMode = "on";
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  </script>
  <style>
    #divb::before,
    #diva::after {
      content: "pseudo element";
    }
    #divba::before {
      content: "before";
    }
    #divba::after {
      content: "after";
    }
  </style>
</head>
<body>

  <a target="_blank"
     title="nsIAccessibleEditableText chrome tests"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=452161">
    Bug 452161
  </a>
  <a target="_blank"
     title="Cache rendered text on a11y side"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=626660">
    Bug 626660
  </a>
  <a target="_blank"
     title="Pseudo element support test"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=1105611">
    Bug 1105611
  </a>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <input id="input"/>

  <div id="div" contenteditable="true"></div>
  <div id="divb" contenteditable="true"></div>
  <div id="diva" contenteditable="true"></div>
  <div id="divba" contenteditable="true"></div>

  <iframe id="frame"/>
</body>
</html>
